package com.hb.trans.mvp.ui.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import com.ctcnit.templatepro.global.MyGlideModule
import com.hb.trans.R
import com.hb.trans.bean.Navigation
import org.jetbrains.anko.find


class NavigationAdapter(val mContext: Context, val serves: MutableList<Navigation>, val layoutId: Int) : BaseAdapter() {

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        var mHolder: MyViewHolder
        var view: View? = null
        if (convertView == null) {
            view = View.inflate(mContext, layoutId, null)
            mHolder = MyViewHolder()
            mHolder.ic = view.find(R.id.ivIcon)
            mHolder.tvName = view.find(R.id.tvServeName)
            view.tag = mHolder
        } else {
            view = convertView
            mHolder = convertView.tag as MyViewHolder
        }
        mHolder.tvName!!.text = serves[position].title
        MyGlideModule.loadDefault(mContext, serves[position].pic, mHolder.ic!!)
        return view!!
    }

    override fun getItem(position: Int): Navigation = serves[position]

    override fun getItemId(position: Int): Long = position.toLong()

    override fun getCount(): Int = serves.size

    inner class MyViewHolder {
        var ic: ImageView? = null
        var tvName: TextView? = null
    }


}